from langchain_openai import ChatOpenAI
from langchain_core.output_parsers import StrOutputParser

from langchain.prompts import PromptTemplate

from langchain_core.messages import (
    AIMessage,  # 等价于OpenAI接口中的assistant role
    HumanMessage,  # 等价于OpenAI接口中的user role
    SystemMessage  # 等价于OpenAI接口中的system role
)
from langfuse.callback import CallbackHandler
from langfuse import Langfuse

# 加载 .env 到环境变量
from langfuse.openai import openai  # OpenAI integration
from dotenv import load_dotenv, find_dotenv

_ = load_dotenv(find_dotenv())

# 设置 API 类型为 'openai'（默认OpenAI服务）或 'azure'（Azure上的OpenAI服务）
openai.api_type = "openai"  # 或者 "azure"

# 定义输出解析器
strParser = StrOutputParser()


def get_model(model="gpt-3.5-turbo", temperature=0, max_tokens=1000, model_kwargs={}):
    return ChatOpenAI(model=model, temperature=temperature, max_tokens=max_tokens, model_kwargs=model_kwargs)
